class Solution(object):
    def isIsomorphic(self, s, t):
        """
        :type s: str
        :type t: str
        :rtype: bool
        """
        dict1, dict2 = {}, {}
        if len(s)!=len(t):return False
        for i in range(len(s)):
            ch1 = ord(s[i])
            ch2 = ord(t[i])
            if ch1 not in dict1 and ch2 not in dict2:
                dict1.update({ch1:ch2})
                dict2.update({ch2:ch1})
            elif ch1 in dict1 and ch2 in dict2 and dict1[ch1]==ch2 and dict2[ch2]==ch1:
                continue
            else:
                return False
        return True

print(Solution().isIsomorphic("foo", "bar"))